package com.springcloud.controller;

import com.springcloud.mq.MyOutputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 咕唧
 * @Date 2022/6/28 20:07
 * @Version 1.0
 */
@RestController
public class TestController {
    private MyOutputStream myOutputStream;

    @Autowired
    public void setMyOutputStream(MyOutputStream myOutputStream) {
        this.myOutputStream = myOutputStream;
    }

    @GetMapping("/send")
    public String sendMessage(String msg){
        //获取通道
        MessageChannel channel = myOutputStream.messageChannel();
        //发送消息
        channel.send(new GenericMessage<String>(msg));
        return "success";
    }
}
